<template>

    <el-button @click="backToList()">
        返回
    </el-button>
    <div class="myInputPad">
    标题:<el-input v-model="reqParam.title" />
    </div>
    <div class="myInputPad">
    标签:
    <i v-for="item in tagList">
        <input type="checkbox" :id="item.id" :value="item.id" v-model="reqParam.tagIdList">
        <label :for="item.id">{{ item.name }}</label>
    </i>
    </div>
<br>
    <div class="myInputPad">
类型:
    <el-select v-model="reqParam.type" placeholder="选择类型">
        <el-option v-for="item in typeMap" :value="item[0]" :label="item[1]">{{ item[1] }}</el-option>
    </el-select>
    </div>

    <div class="myInputPad">
   正文描述
    <el-input type="textarea" v-model="reqParam.content" size="large" />
    </div>
        <el-form-item style="margin-top: 20px">
            <el-button type="primary" @click="submitForm()">
                保存
            </el-button>
            <el-button type="primary" @click="submitForm()">
                保存并发布
            </el-button>
            <el-button @click="resetForm()">
                重置
            </el-button>
            <el-button @click="getInfo()">
                获取数据
            </el-button>
        </el-form-item>


</template>

<script setup>

import { ref } from 'vue'
import {Plus} from "@element-plus/icons-vue";
import {getPostList} from "@/api/request";
import {ElMessage} from "element-plus";
import router from "@/api/routerConfig";

const loginUserId = ref("")
const loginUserName = ref("")


const typeMap = ref(new Map([
    ['1', "求助"],
    ['2', "教程"],
    ['3', "讨论"],
    ['4', "分享"],
    ['5', "其他"]
]))

const reqParam = ref({
    loginUserId: "",
    loginUserName: "",
    creatorId: "",
    creatorName: "",
    gmtCreateTime: "",
    modifierId: "",
    modifierName: "",
    gmtModifyTime: "",
    id: "",
    title: "",
    type: "",
    content: "",
    tagIds: "",
    tagIdList: [],
    fileUrls: "",
    fileUrlList: [],
    status: "",
    backReason: "",
    saveType: ""
})

const tagList = ref([])



async function submitForm() {
    let resp = await getPostList(
        reqParam.value,
        "/post/add"
    )
    if (resp.code === 200) {
        ElMessage.success("提交成功")
    }else {
        ElMessage.error("提交失败")
    }
    router.back()
}

async function getInfo() {
    let resp = await getPostList(
        {
            type: 1
        }, "/tag/listByType"
    )
    tagList.value = resp.data
}

function backToList() {
    router.back()
}


function resetForm() {
    reqParam.value = {
        loginUserId: "",
        loginUserName: "",
        creatorId: "",
        creatorName: "",
        gmtCreateTime: "",
        modifierId: "",
        modifierName: "",
        gmtModifyTime: "",
        id: "",
        title: "",
        type: "",
        content: "",
        tagIds: "",
        tagIdList: [],
        fileUrls: "",
        fileUrlList: [],
        status: "",
        backReason: "",
        saveType: ""
    }
}

</script>

<style scoped>

.myInputPad {
    margin-top: 30px;
    font-size: 1.5em;
}

</style>